package ctx

import (
	"fmt"
	"framework/httpz/response"
	"go/ast"
	"go/parser"
	"go/token"
	"time"

	"github.com/kataras/iris/v12"
)

func AstDemo(ctx iris.Context) {

	// 源代码
	src := `
package main

import "fmt"

func main() {
    fmt.Println("Hello, AST!")
}
`

	// 创建文件集
	fset := token.NewFileSet()

	// 解析源代码
	f, err := parser.ParseFile(fset, "", src, parser.ParseComments)
	if err != nil {
		fmt.Println("解析错误:", err)
		return
	}

	// 打印AST结构
	ast.Print(fset, f)

	response.Sucess(ctx, iris.Map{
		"unix_time": time.Now().Format(time.RFC3339),
	})
}
